package com.dreamwhale.machinery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.config.StringUtils;
import com.dreamwhale.machinery.entity.Machinist;
import com.dreamwhale.machinery.dao.MachinistMapper;
import com.dreamwhale.machinery.service.MachinistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 机修师 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-06-15
 */
@Service
public class MachinistServiceImpl extends ServiceImpl<MachinistMapper, Machinist> implements MachinistService {

    @Resource
    private MachinistMapper machinistMapper;

    @Override
    public int insertMachinists(Machinist machinist) {
        machinist.setCreateTime(LocalDateTime.now());
        return machinistMapper.insert(machinist);
    }

    @Override
    public List<Machinist> selectMachinistsByCity(String provinceCode, String cityCode, Integer classifyId) {

        QueryWrapper<Machinist> queryWrapper = new QueryWrapper<>();

        if (provinceCode != null) {
            queryWrapper.eq("province_code", provinceCode);
        }
        if (StringUtils.isNotEmpty(cityCode)) {
            queryWrapper.eq("city_code", cityCode);
        }
        if (classifyId != null) {
            queryWrapper.eq("classify_id", classifyId);
        }
        queryWrapper.eq("ma_del", 0).eq("ma_audit", 1);
        return machinistMapper.selectList(queryWrapper);
    }

    @Override
    public Machinist selectMachinistsByMaId(Integer machinistId) {
        return machinistMapper.selectById(machinistId);
    }
}
